<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Open persistent MS SQL connection</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mssql-num-rows.html">mssql_num_rows</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mssql-query.html">mssql_query</a></div>
 <div class="up"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.mssql-pconnect" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mssql_pconnect</h1>
  <p class="verinfo">(PHP 4, PHP 5, PECL odbtp &gt;= 1.1.1)</p><p class="refpurpose"><span class="refname">mssql_pconnect</span> &mdash; <span class="dc-title">Open persistent MS SQL connection</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.mssql-pconnect-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">resource</span> <span class="methodname"><strong>mssql_pconnect</strong></span>
    ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$servername</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$username</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$password</code></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$new_link</code><span class="initializer"> = false</span></span>
  ]]]] )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>mssql_pconnect()</strong></span> acts very much like
   <span class="function"><a href="function.mssql-connect.html" class="function">mssql_connect()</a></span> with two major differences.
  </p>
  <p class="para">
   First, when connecting, the function would first try to find a
   (persistent) link that&#039;s already open with the same host,
   username and password.  If one is found, an identifier for it
   will be returned instead of opening a new connection.
  </p>
  <p class="para">
   Second, the connection to the SQL server will not be closed when
   the execution of the script ends.  Instead, the link will remain
   open for future use (<span class="function"><a href="function.mssql-close.html" class="function">mssql_close()</a></span> will not
   close links established by <span class="function"><strong>mssql_pconnect()</strong></span>).
  </p>
  <p class="para">
   This type of links is therefore called &#039;persistent&#039;.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mssql-pconnect-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">servername</code></em></dt>

     <dd>

      <p class="para">
       The MS SQL server. It can also include a port number. e.g. 
       <em>hostname:port</em>.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">username</code></em></dt>

     <dd>

      <p class="para">
       The username. 
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">password</code></em></dt>

     <dd>

      <p class="para">
       The password. 
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">new_link</code></em></dt>

     <dd>

      <p class="para">
       If a second call is made to <span class="function"><strong>mssql_pconnect()</strong></span> with
       the same arguments, no new link will be established, but instead, the
       link identifier of the already opened link will be returned. This
       parameter modifies this behavior and makes
       <span class="function"><strong>mssql_pconnect()</strong></span> always open a new link, even if
       <span class="function"><strong>mssql_pconnect()</strong></span> was called before with the same
       parameters.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mssql-pconnect-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a positive MS SQL persistent link identifier on success, or
   <strong><code>FALSE</code></strong> on error.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mssql-pconnect-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1516">
    <p><strong>Example #1 <span class="function"><strong>mssql_pconnect()</strong></span> using the <em><code class="parameter">new_link</code></em> parameter</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Connect&nbsp;to&nbsp;MSSQL&nbsp;and&nbsp;select&nbsp;the&nbsp;database<br /></span><span style="color: #0000BB">$link1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">'MANGO\SQLEXPRESS'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'sa'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phpfi'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mssql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">'php'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$link1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;a&nbsp;new&nbsp;link<br /></span><span style="color: #0000BB">$link2&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mssql_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">'MANGO\SQLEXPRESS'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'sa'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phpfi'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mssql_select_db</span><span style="color: #007700">(</span><span style="color: #DD0000">'random'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$link2</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.mssql-num-rows.html">mssql_num_rows</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.mssql-query.html">mssql_query</a></div>
 <div class="up"><a href="ref.mssql.html">Mssql 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
